/**
 * 表单输入框提示
 */
define(function (require, exports, module) {


    var $body = $("body"), $win = $(window);


    return function ($obj, message, dir) {
        var xy = function ($obj, $tip, dir) {
            var gap = 16;//提示和目标元素的间距
            var o_w = $obj.outerWidth(), o_h = $obj.outerHeight(),
                o_top = $obj.offset().top, o_left = $obj.offset().left;

            var t_h = $tip.outerHeight(), t_w = $tip.outerWidth()
            if (dir == "right") {
                $tip.css({
                    left: o_left + o_w + gap,
                    top: o_top + (o_h - t_h) / 2
                })
            } else if (dir == "left") {
                $tip.css({
                    left: o_left - t_w - gap,
                    top: o_top + (o_h - t_h) / 2
                })
            }else if (dir == "top") {
                $tip.css({
                    left: o_left +(o_w-t_w)/2,
                    top: o_top-t_h-gap
                })
            }
        }
        var $tip = null;

        return {
            show: function (msg) {
                if (msg) {
                    message = msg
                }
                $(".G_ipt_tip").remove();
                $tip = $(template("ui/tip", {"message": message}));
                dir && $tip.addClass(dir);
                message && $tip.find("span").text(message);
                $body.append($tip.hide());
                $tip.fadeIn(function () {
                    var self = this;
                    setTimeout(function () {
                        self.remove();
                    }, 2000)
                })
                xy($obj, $tip, dir);
            },
            remove: function () {
                $tip.remove();
                $obj.removeData("is_exist")
            },
            change: function (message) {
                $tip.find("span").text(message);
                xy($obj, $tip, dir);
            }
        }
    }
})
